﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net;
using System.IO;
using System.Web.Script.Serialization;
using System.Messaging;

namespace UnitTests
{
    [TestClass]
    public class UnitTESTS
    {
        [TestMethod]
        public void TestSOAP()
        {
            PropietariosWS.PropietarioServiceClient proxy = new PropietariosWS.PropietarioServiceClient();
            PropietariosWS.Propietario propietario = proxy.ObtenerPropietario(1,304);
            Assert.AreEqual(1, propietario.Torre);
            Assert.AreEqual(304, propietario.Dpto);
        }

        [TestMethod]
        public void TestREST()
        {
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://localhost:20000/AreasComunesService.svc/AreasComunes");
            req.Method = "GET";
            HttpWebResponse res = (HttpWebResponse)req.GetResponse();
            StreamReader reader = new StreamReader(res.GetResponseStream());
            string areaComunJson = reader.ReadToEnd();
            JavaScriptSerializer js = new JavaScriptSerializer();
            List<AreaComun> areaComunObtenida = js.Deserialize<List<AreaComun>>(areaComunJson);
            Assert.AreEqual(17, areaComunObtenida.Count);
        }

        [TestMethod]
        public void TestRESTMensajes()
        {
            string ruta = "http://localhost:23000/ReservaService.svc/Reservas/1304212";
            HttpWebRequest req = (HttpWebRequest)WebRequest
                .Create(ruta);
            req.Method = "DELETE";
            var res = (HttpWebResponse)req.GetResponse();
            StreamReader reader = new StreamReader(res.GetResponseStream());
            string reservaJson = reader.ReadToEnd();
            JavaScriptSerializer js = new JavaScriptSerializer();
            string msjResultado = js.Deserialize<string>(reservaJson);

            string rutaCola = @".\private$\rkanashiro";
            MessageQueue cola = new MessageQueue(rutaCola);
            Assert.AreEqual(4, cola.GetAllMessages().Length);
        }
    }
}
